package com.cqc.dialogfragment01;

import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "MainActivity";
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private DialogFragment01 frag;
    private DialogFragment02 frag2;
    private DialogFragment03 frag3;
    private DialogFragment04 frag4;
    private DialogFragment05 frag5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        btn4 = (Button) findViewById(R.id.btn4);
        btn5 = (Button) findViewById(R.id.btn5);

        ArrayList<String> items = new ArrayList<>();
        items.add("山东");
        items.add("江苏");
        items.add("浙江");
        frag = new DialogFragment01();
        frag2 = new DialogFragment02();
        frag3 = new DialogFragment03();
        frag4 = DialogFragment04.getInstance("请选择方式","取消",items);
        frag5 = new DialogFragment05();

        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);

        frag4.setOnClickListener(new DialogFragment04.OnClickListener() {
            @Override
            public void onClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(view.getContext(), "position="+position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                frag.show(getSupportFragmentManager(), "frag");
                break;
            case R.id.btn2:
                frag2.show(getSupportFragmentManager(), "frag2");
                break;
            case R.id.btn3:
                frag3.show(getSupportFragmentManager(), "frag3");
                break;
            case R.id.btn4:
                frag4.show(getSupportFragmentManager(), "frag4");
                break;
            case R.id.btn5:
                frag5.show(getSupportFragmentManager(), "frag5");
                break;
        }
    }


    //            dialog.setOnKeyListener(new DialogInterface.OnKeyListener()
    //
    //    {
    //        @Override
    //        public boolean onKey (DialogInterface dialog,int keyCode, KeyEvent event){
    //        switch (event.getAction()) {
    //            case android.view.KeyEvent.ACTION_DOWN:
    //                Toast.makeText(getActivity(), "ACTION_DOWN", Toast.LENGTH_SHORT).show();
    //                break;
    //            case android.view.KeyEvent.ACTION_UP:
    //                Toast.makeText(getActivity(), "ACTION_UP", Toast.LENGTH_SHORT).show();
    //                break;
    //            case android.view.KeyEvent.ACTION_MULTIPLE:
    //                Toast.makeText(getActivity(), "ACTION_MULTIPLE", Toast.LENGTH_SHORT).show();
    //                break;
    //        }
    //        return false;
    //    }
    //    });
}
